﻿#region Using directives

using System;
using System.Collections.Generic;
using System.Text;

#endregion

using Weazel.Badger.Vhdl.Types;

namespace Weazel.Badger.Vhdl
{
  public enum PortDirection
  {
    In,
    Out,
    InOut
  };

  public class Port : Signal
  {
    private Vhdl.Types.Type type;

    private PortDirection portDirection;
    public PortDirection PortDirection
    {
      get
      {
        return portDirection;
      }

      set
      {
        portDirection = value;
      }
    }

    public void Resolve(Entity entity, Process process)
    {
			/*
      if (portDirection == PortDirection.In)
      {
				SetActualType(entity, process, type);
      }
      else
      {
        GetPossibleTypes();
				SetActualType(entity, process, type);
      }
			 * */
    }

		private int declarationPosition;
		public int DeclarationPosition
		{
			get { return declarationPosition; }
		}


    public override TypeSet GetPossibleTypes()
    {
      if (portDirection == PortDirection.In)
        return new TypeSet(type);
      else
        return base.GetPossibleTypes();
    }

		public override void SetActualType(Entity entity, Process process, Statements.StatementCollection statements, Vhdl.Types.Type type)
    {
			base.SetActualType(entity, process, statements, this.type);
    }

    public Port(Vhdl.Types.Type type, GezelType gezelType, string name, int position) : base(type, gezelType, name)
    {
      this.type = type;
      this.portDirection = PortDirection.In;
			this.declarationPosition = position;
    }

    public Port(Vhdl.Types.Type type, GezelType gezelType, string name, PortDirection direction, int position) : this(type, gezelType, name, position)
    {
      this.type = type;
      this.portDirection = direction;
			this.declarationPosition = position;
    }

    public string GetDeclaration()
    {
      string dir =
         portDirection == PortDirection.In ? "in"
       : portDirection == PortDirection.Out ? "out"
       : "inout";

      string type = !(this.Type == Types.Types.Undefined) ? this.Type.ToString() : "TYPE NOT SET";

      return String.Format("{0} : {1} {2}", Name, dir, type);
    }
  }
}
